import {fetchUserList} from '../services/testList'
export default {

    namespace: 'testList',

    state: {
        tableData: {
            list: [],
            page: 1,
            page_size: 10
        }
    },

    effects: {
        *fetchUserList(action, { put, call, select }) {
            const res = yield call(fetchUserList, {
                _page: 1,
                _limit: 5
            })
            yield put({
                type: 'changeState',
                payload: {
                    tableData: {
                        list: res,
                        page: 1,
                        page_size: 5
                    }
                }
            })
        }
    },

    reducers: {
        changeState(state, action) {
            return {
                ...state,
                ...action.payload
            }
        },
        create(state, action) {
            const newList = state.tableData.list
            newList.push(action.payload)
            return {
                ...state,
                tableData: {
                    ...state.tableData,
                    list: newList
                }
            };
        },
    },

};
